/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import controller.DBAccess;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author STEVEN_PHAN
 */
public class MonHoc {

    private String ID;
    private String Name;

    /**
     * @return the ID
     */
    public String getID() {
        return ID;
    }

    /**
     * @param ID the ID to set
     */
    public void setID(String ID) {
        this.ID = ID;
    }

    /**
     * @return the Name
     */
    public String getName() {
        return Name;
    }

    /**
     * @param Name the Name to set
     */
    public void setName(String Name) {
        this.Name = Name;
    }

    public boolean checkId() {
        ResultSet rs;
        String str = "Select ID from MonHoc where ID = ";
        str += "'" + this.ID + "'";
        rs = DBAccess.getData(str);
        if (rs!= null) {
            return true;
        } else {
            return false;
        }
    }

    public void insert() {
        boolean f ;
        f = checkId();
        if(f == true){
            JOptionPane.showMessageDialog(null, "Trung ID");
            return;
        }
        int rs;
        String str = "insert into MonHoc values";
        str += "('" + this.ID + "',";
        str += "'" + this.Name + "')";
        rs = DBAccess.insertData(str);
        if (rs > -1) {
            JOptionPane.showMessageDialog(null, "Insert thanh cong");
        } else {
            JOptionPane.showMessageDialog(null, "Insert that bai");
        }
        DBAccess.closeConnect();
    }

}
